package com.zls.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

//import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.zls.model.ProductModel;

import com.zls.util.ConnectionHelper;
import com.zls.util.DruidUtil;
import com.zls.util.QueryrunnerWrapper;

public class ProductDaoImpl {	
	
	
	public  List<ProductModel> getAll()  {
		
		String sql="select * from demo";
		List<ProductModel> list = QueryrunnerWrapper.query(sql, new BeanListHandler<ProductModel>(ProductModel.class));
		return list;
		
	}
	
	public  int deleteProductById(int id)  {
		
		String sql="delete from demo where id=?";
		int n=QueryrunnerWrapper.update(sql, id);
		return n;
	}
	
	public  int insertProductByInfo(ProductModel model)  {
		
		String sql="insert into demo values(?,?,?,?,?)";
		int n=0;
		n=QueryrunnerWrapper.update(sql, model.getId(), model.getProName(),
		model.getPrice(),model.getAmount(),model.getDescription());
		return n;
		
	}
	
	public  int updateProductInfo(ProductModel model)  {

		String sql="update demo set proName=?,price=?,amount=?,description=? where id=?";
		int n=0;
		n=QueryrunnerWrapper.update(sql,
	    model.getProName(),model.getPrice(),model.getAmount(),model.getDescription(),model.getId());
		return n;
	}
}
